package cn.tedu.zx.ams.adapter.controller;

import cn.tedu.zx.ams.adapter.mapper.RoleMapper;
import cn.tedu.zx.ams.service.PermissionService;
import cn.tedu.zx.common.restful.JsonResult;
import cn.tedu.zx.pojo.admin.parm.PermissionAddNewParam;
import cn.tedu.zx.pojo.admin.parm.PermissionUpdateParam;
import cn.tedu.zx.pojo.admin.vo.PermissionListItemVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/permission")
@Api(tags = "03. 权限管理模块")
@Slf4j
@Validated
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @Autowired
    private RoleMapper roleMapper;

    @GetMapping("/list")
    @ApiOperation("查询权限列表")
    @ApiOperationSupport(order = 100)
    @PreAuthorize("hasAnyAuthority('/permission/read')")
    public JsonResult<List<PermissionListItemVO>> list(){
        log.debug("开始处理【查询权限列表】的业务");
        List<PermissionListItemVO> list = permissionService.list();
        return JsonResult.ok(list);
    }
/*
    @PostMapping("/update")
    @ApiOperation("修改权限数据")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> update(@Valid PermissionUpdateParam permissionUpdateParam){
        log.debug("开始处理【修改权限数据】的业务");
        permissionService.update(permissionUpdateParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除权限数据")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "权限id", required = true, dataType = "Long"),
    })
    public JsonResult<Void> delete(Long id){
        log.debug("开始处理【删除权限数据】的业务");
        permissionService.delete(id);
        return JsonResult.ok();
    }
    @PostMapping("/addNew")
    @ApiOperation("新增权限数据")
    @ApiOperationSupport(order = 400)
    public JsonResult<Void> addNew(@Valid PermissionAddNewParam permissionAddNewParam){
        log.debug("开始处理【新增权限数据】的业务");
        permissionService.addNew(permissionAddNewParam);
        return JsonResult.ok();
    }*/
}
